import com.sun.xml.internal.ws.handler.HandlerTube;

import java.util.*;

public class 串联所有单词的子串 {
    public static List<Integer> findSubstring(String s, String[] words) {
        //返回值
        List<Integer> res = new ArrayList<>();
        //将words中的单词放入到哈希表中
        Hashtable<String,Integer> map = new Hashtable<>();
        int len = words[0].length();
        putChar(map,words);
        //遍历s

        //添加返回值
        for (Map.Entry<String,Integer> entry:map.entrySet()) {
            res.add(entry.getValue());
        }
        return res;
    }
    public static void putChar(Hashtable<String,Integer> map,String[] words){
        for (int i = 0; i < words.length; i++) {
            //如果hb中有了改单词，改单词的的value++；
            if (map.containsKey(words[i])){
                int val = map.get(words[i]);
                map.put(words[i],val+1);
            }else {
                map.put(words[i],1);
            }
        }
    }
    public static void pushChar(Hashtable<String,Integer> map,String s){
        int val = map.get(s);
        map.put(s,val-1);
    }

    public static void haskey(String s, Hashtable<String,Integer> map,int len,int l){
        String str = null;
        Hashtable<String, Integer> map1 = map;
        for (int j = 0; j < s.length(); j = j + len) {
            for (int i = j+len; i < s.length(); i = i + len) {
                String s1 = s.substring(i - len, i);
                boolean b = map.containsKey(s1);
                if (b){
                    pushChar(map1,s1);
                    str = str.concat(s1);
                }else {
                    s = null;
                    continue;
                }
                if (s.length() == l*len){
                    break;
                }
            }
        }

    }
    public static void main(String[] args) {
        List<Integer> res = findSubstring("sss", new String[]{"qwe", "sad", "qwe"});
        for (Integer i:res) {
            System.out.println(i.toString());
        }
    }
}
